package com.ymatou.iapi.godmch.testcase;

import java.text.SimpleDateFormat;
import java.util.List;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.godmch.parameter.createDepotBean;
import com.ymatou.iapi.godmch.parameter.getDepotListBean;
import com.ymatou.iapi.godmch.service.createDepotCall;
import com.ymatou.iapi.godmch.service.getDepotListCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.shenqi.GodmchManageCallService;
import com.ymttest.database.model.godmch.mch_depot_info;
import com.ymttest.database.model.godmch.mch_depot_infoExample;
import com.ymttest.database.sqlwapper.godmch.mch_depot_infoWapper;
/**
*商户仓库列表
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_getDepotList{
	private static getDepotListBean bean;
	private static getDepotListCall call;
	
	createDepotBean cbean=new createDepotBean ();
	createDepotCall ccall=new createDepotCall();
	 SimpleDateFormat sdf=new SimpleDateFormat("yyyy-mm-dd HH:mm:ss");
    	
	mch_depot_infoWapper depotWapper;
	mch_depot_infoExample example;
	
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("商户仓库列表");
	}

	@Before
	public void caseUp() {
		bean=new getDepotListBean();
		call=new getDepotListCall();
		
		depotWapper=new mch_depot_infoWapper();
		example=new mch_depot_infoExample();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(call.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	
	private void check_verify() throws InterruptedException {
		Logger.verifyEquals("200", call.getStatus1(), "验证status");
		int currPage,pageSize=0;
        if(bean.getPageIndex()==null || bean.getPageIndex()==0) currPage=1;
		 else   currPage=bean.getPageIndex(); 
        
		if(bean.getPageSize()==null|| bean.getPageSize()==0) pageSize=5;
		 else  pageSize=bean.getPageSize(); 
		
		example.createCriteria().andMchIdEqualTo(bean.getMchId());
		if(bean.getDepotTitle()!=null && bean.getDepotTitle()!="")  example.createCriteria().andDepotTitleEqualTo(bean.getDepotTitle());
		
        List<mch_depot_info> lst=depotWapper.selectByExample(example);
    	Logger.verifyEquals(call.getTotal(),lst.size(), "验证总条数");

		 //从第几条数据开始
        int firstIndex = (currPage - 1) * pageSize;
        //到第几条数据结束
        int lastIndex = currPage * pageSize;
        lastIndex= lastIndex>lst.size()?lst.size():lastIndex;
        if( firstIndex>lastIndex)
        	 lst=lst.subList(0, 0);
        else
             lst=lst.subList(firstIndex, lastIndex); //直接在list中截取
        
        List<mch_depot_info> return_depots=call.getDepots();

        int count=0;
        for(mch_depot_info DB_depot:lst)
        {
        	Logger.verifyEquals(return_depots.get(count).getDepotId(), DB_depot.getDepotId(), "验证第"+count+"个数据库字段DepotId与返回的是否一致");
        	Logger.verifyEquals(return_depots.get(count).getDepotTitle(), DB_depot.getDepotTitle(), "验证第"+count+"个数据库字段DepotTitle与返回的是否一致");
        	Logger.verifyEquals(return_depots.get(count).getRemark(), DB_depot.getRemark(), "验证第"+count+"个数据库字段Remark与返回的是否一致");
        	Logger.verifyEquals(sdf.format(return_depots.get(count).getCreateTime()), sdf.format(DB_depot.getCreateTime()), "验证第"+count+"个数据库字段CreateTime与返回的是否一致");
        	
        	//新增 20200619
        	Logger.verifyEquals(return_depots.get(count).getBuyerTitle(), DB_depot.getBuyerTitle(), "验证第"+count+"个数据库字段BuyerTitle与传入的是否一致");
        	Logger.verifyEquals(return_depots.get(count).getPicUrl(), DB_depot.getPicUrl(), "验证第"+count+"个数据库字段PicUrl与传入的是否一致");
        	
        	count++;
        }

	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getDepotList_001() {
		Logger.start(true,"商户仓库列表--验证商户1条仓库,查询第1页");
		try {
			Integer mchId = GodmchManageCallService.CreateSellerMch();
			GodmchManageCallService.createDepot(mchId);
			bean.setMchId(mchId);
			bean.setPageIndex(1);
			bean.setPageSize(5);
			call.setData(bean);
			call.callService();			
				
			check_verify();
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getDepotList_002() {
		Logger.start(true,"商户仓库列表--验证商户1条仓库,查询第2页");
		try {
			Integer mchId = GodmchManageCallService.CreateSellerMch();
			GodmchManageCallService.createDepot(mchId);
			bean.setMchId(mchId);
			bean.setPageIndex(2);
			bean.setPageSize(5);
			call.setData(bean);
			call.callService();			
			
			check_verify();		
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getDepotList_003() {
		Logger.start(true,"商户仓库列表--验证商户2条仓库,查询第1页");
		try {
			Integer mchId = GodmchManageCallService.CreateSellerMch();
			GodmchManageCallService.createDepot(mchId);
			GodmchManageCallService.createDepot(mchId);
			bean.setMchId(mchId);
			bean.setPageIndex(1);
			bean.setPageSize(5);
			call.setData(bean);
			call.callService();			
			
			check_verify();				
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getDepotList_004() {
		Logger.start(true,"商户仓库列表--验证商户2条仓库,查询第2页");
		try {
			Integer mchId = GodmchManageCallService.CreateSellerMch();
			GodmchManageCallService.createDepot(mchId);
			GodmchManageCallService.createDepot(mchId);
			bean.setMchId(mchId);
			bean.setPageIndex(2);
			bean.setPageSize(5);
			call.setData(bean);
			call.callService();			
			
			check_verify();		
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getDepotList_005() {
		Logger.start(true,"商户仓库列表--验证商户3条仓库,查询第2页");
		try {
			Integer mchId = GodmchManageCallService.CreateSellerMch();
			GodmchManageCallService.createDepot(mchId);
			GodmchManageCallService.createDepot(mchId);
			GodmchManageCallService.createDepot(mchId);
			bean.setMchId(mchId);
			bean.setPageIndex(2);
			bean.setPageSize(5);
			call.setData(bean);
			call.callService();			
			
			check_verify();	
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getDepotList_006() {
		Logger.start(true,"商户仓库列表--验证查询第9999页");
		try {
			Integer mchId = GodmchManageCallService.CreateSellerMch();
			GodmchManageCallService.createDepot(mchId);
			bean.setMchId(mchId);
			bean.setPageIndex(9999);
			bean.setPageSize(5);
			call.setData(bean);
			call.callService();			
			
			check_verify();				
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getDepotList_007() {
		Logger.start(true,"商户仓库列表--验证mchId为空");
		try {
//			Integer mchId = GodmchManageCallService.CreateSellerMch();
//			GodmchManageCallService.createDepot(mchId);
			//bean.setMchId(mchId);
			bean.setPageIndex(1);
			bean.setPageSize(5);
			call.setData(bean);
			call.callService();				
			
			Logger.verifyEquals("4001", call.getStatus1(), "验证status");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}